/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.        */
/*                                                                 */
/*  NAME      = wtc_typed_mbstring.c                               */
/*  NOTE      =                                                    */
/*  DATE      = 2015/08/26 by songbb                               */
/*******************************************************************/

#include "frreport_comm.h"
#include "frct_comm.h"

#include "../wtc_core.h"
#include "../wtc_comm.h"
#include "../wtc_mar.h"
#include "wtc_typed_mbstring.h"

int wtc_typed_mbstring_tmpostrecv(Conntrack *p_st_conn
                                , L7session_wtc *p_st_sess
                                , L7_wtc_packet *p_st_wtc_packet
                                , int i_recv_size
                                , Frreport_body_data *p_st_body)
{
    WTC_PRINT_INFO("wtc_typed_mbstring_tmpostrecv...\n");
    L7_session *p_st_session = frct_get_session(p_st_conn);
    L7session_wtc_private *p_st_session_private = (L7session_wtc_private *) frct_get_session_private(p_st_session);
    L7_wtc_stmt *p_st_wtc_stmt = p_st_session_private->p_st_wtc_stmt;
    char *p_bytes = NULL;
    L7_wtc_mbstring *p_st_wtc_mbstring = NULL;
    Frlist_node *p_st_node = NULL;

    if ((p_bytes = (char *) frmalloc(i_recv_size * sizeof(char))) == NULL)
    {
        WTC_MALLOCK_ERR;
        goto error;
    }

    if (bytebuff_get_bytes(p_st_wtc_packet->p_st_packet, p_bytes, (unsigned int) i_recv_size) != FR_SUCC)
        goto error;

    if ((p_st_wtc_mbstring = (L7_wtc_mbstring *) frmalloc(sizeof(L7_wtc_mbstring))) == NULL)
    {
        WTC_MALLOCK_ERR;
        goto error;
    }
    memset(p_st_wtc_mbstring, 0x00, sizeof(L7_wtc_mbstring));
    p_st_wtc_mbstring->ui_index = 1;
    p_st_wtc_mbstring->p_mbstring = p_bytes;
    p_st_wtc_mbstring->ui_mbstring_len = (unsigned int) i_recv_size;
    p_st_node = frlist_node_create(p_st_wtc_mbstring);
    frlist_push(p_st_wtc_stmt->p_list_mbstring, p_st_node);
    
    return FR_SUCC;
error:
    wtc_free((void **) &p_bytes);
    return FR_FAIL;
}

int wtc_typed_mbstring_tmpostrecv_fad(int i_recv_size
                                    , char *p_payload
                                    , unsigned int ui_payload_len
                                    , unsigned int *p_ui_offset)
{
    return wtc_skip(p_payload, ui_payload_len, p_ui_offset, i_recv_size);
}
